﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace BSPortal.Usercontrol.Admin.Book.Order
{
    public partial class frmOrderDetailOfDetail : System.Web.UI.Page
    {
        private short id = 0;
        private MainService service = new MainService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }





        void LoadData()
        {
            string str = Request["OrderDetailId"];
            if (str == null)
            {
                txtId.Text = "";
                txtAmout.Text = "";

            }
            else
            {
                id = short.Parse(str);
                var data = service.GetOrderDetailById(short.Parse(str));
                if (data != null)
                {
                    txtId.Text = data.ProductId.ToString();
                    txtId.Enabled = false;
                    txtAmout.Text = data.Amount.ToString();
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strOrderDetailId = Request["OrderDetailId"];
            string strOrderId = Request["OrderId"];
            if (strOrderId == null || strOrderDetailId==null)
            {
                int retcode = service.CreateOrderDetail(short.Parse(strOrderId), short.Parse(txtAmout.Text), short.Parse(txtId.Text));
                lblStatus.Text = retcode == (int)Common.RetCode.SUCESS ? "Thêm thành công..." : "Thêm không thành công...";
                hdModified.Value = "true";
            }
            else
            {
                int retcode = service.UpdateOrderDetail(short.Parse(strOrderDetailId), short.Parse(txtAmout.Text), short.Parse(txtId.Text));
                lblStatus.Text = retcode == (int)Common.RetCode.SUCESS ? "Cập nhật thành công..." : "Cập nhật không thành công...";
                hdModified.Value = "true";
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtAmout.Text = string.Empty;
        }


    }
}
